package com.ciwong.epaper.modules.evaluate.ui.dialogfragment;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.IntegerRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.BottomSheetDialogFragment;
import android.view.View;

import com.ciwong.epaper.R;

import java.util.ArrayList;
import java.util.List;


/**
 * description：//底部弹窗
 * author：loco
 * email：lzh838330255@163.com
 * date：on 2018/3/26
 */


public abstract class BaseDialogFragment<E> extends BottomSheetDialogFragment implements View.OnClickListener {
    private BottomSheetBehavior mBehavior;
    protected List<E> list = new ArrayList<>();

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
        View view = View.inflate(getContext(), setView(), null);
        dialog.setContentView(view);
        mBehavior = BottomSheetBehavior.from((View) view.getParent());
        //是背景色透明
        ((View) view.getParent()).setBackgroundColor(getResources().getColor(android.R.color.transparent));
        initView(view);
        initData();
        return dialog;
    }

    protected abstract void initData();

    abstract @LayoutRes
    int setView();

    abstract void initView(View view);

    abstract void onClick(@LayoutRes int resID);

    @Override
    public void onStart() {
        super.onStart();
        mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);//全屏展开
        mBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {

            }
        });
    }

    @SuppressLint("ResourceType")
    @Override
    public void onClick(View v) {
        int i = v.getId();
        onClick(i);
        mBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
    }


    public ICheckScoreListener mListener;

    public void setCheckScoreListener(ICheckScoreListener listener) {
        mListener = listener;
    }

    public interface ICheckScoreListener {
        void checkScore(int range);
    }
}
